	var rootPath = getRootPath();
	
		// 推荐车型选择
		function selectCarmodel(){
			 $("#maintainMainDiv").hide();
			 $("#maintainMainDiv").removeClass("active in");
			 $("#selectCarxin").hide();
			 $("#selectCarxin").removeClass("active in");
			 $("#selectCarmodel").show();
			 //初始化界面
			 $("#selectCarmodel").html("");
			 $("#selectCarmodel").addClass("active in");
			
			$.ajax({
				method : 'get',
				url : rootPath+'/leads/api/v1/brands?brandCode=GMMC',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("数据刷新失败");
				},
				success : function(resultData){
					var wholeHtml = '<h3>车系选择</h3>';
					$.each(resultData,function(memberInfoIndex,brandexhibitiondto){
						var carModelHtml = '';
						var series = brandexhibitiondto.series;
						$.each(series,function(serIndex,serdto){
						carModelHtml = carModelHtml + '<a onclick="sureCar('+ serIndex +')" class="list-group-item">'+ serdto.seriesName +'</a>'
													+ '<input class="hidden" id="mm'+  serIndex +'" value="'+serdto.seriesName +'">'
													+ '<input class="hidden" id="mc'+  serIndex +'" value="'+serdto.seriesCode +'">'

						});
					    wholeHtml += carModelHtml;
					});
					
					$("#selectCarmodel").append(wholeHtml);
				}
			});
		};
		//确认选择
		function sureCar(obj){
			var mm=$("#mm"+obj).val();
			 $("#recommendedcar").html(mm);
			 $("#seriesCode").val($("#mc"+obj).val());
			 $("#selectCarmodel").hide();
			 $("#selectCarmodel").removeClass("active in");
			 $("#maintainMainDiv").show();
			 //初始化界面
			 $("#maintainMainDiv").addClass("active in");
			 $("#carXin").html($("#"+obj).val());
			 if($("#carXin").html()==$("#recommendedcar").html()){
					$("#carXin").html("");
				 }
		}
		function addCounseor(){
			$("#Counselor").html($("#seviceUser").find("option:selected").attr("userName"));
			$("#conselorBtn").click();
		};
		
		//定位所在定经销商,二级页面
		function selectNowDealer(obj){
			 $("#sou").val("");
			 $("#firstImg").hide();
			 $("#maintainMainDiv").hide();
			 $("#maintainMainDiv").removeClass("active in");
			 $("#maintainDealerDiv").hide();
			 $("#maintainDealerDiv").removeClass("active in");
			 $("#nowDealerDiv").show();
			 $("#dealerDiv").html("");
			 //初始化界面
			 $("#nowDealerDiv").addClass("active in");
				//根据城市名获取所在地经销商列表
					$.ajax({
						method : 'get',
						url : rootPath+'/maintain/api/v1/maintainDealer?regionName='+ $("#regionName").val()+'&dealerCode='+ $("#dealerCode").val()+'',
						error:function(XMLHttpRequest, ajaxOptions, thrownError){
							//alert("未连接服务器!");
						},
						success : function(resultData){
							
							var wholeHtml = '';
							var  Km = '';
							$.each(resultData,function(maintainDealerIndex,maintainDealerObj){
								
								var findDealerHtml = '';
								var lat1 = maintainDealerObj.latitude;
								var lng1 = maintainDealerObj.longitude;
								var lat2 = $("#latitude").val();
								var lng2 = $("#longitude").val();
								Km = GetDistance(lat1,lng1,lat2,lng2).toFixed(2);
								if(lat1==null||lat1=="0"||lng1==null||lng1=="0"){var distance = "暂无";}
								else{var distance = Km + '千米';}
								
									if(maintainDealerObj.remark =='首选店'){
										$("#KmFirst").show();
										$("#nameFirst").html(maintainDealerObj.dealerName);
										$("#distanceFirst").html(distance);
										$("#addrFirst").html(maintainDealerObj.detailAddress);
										$("#codeFirst").val(maintainDealerObj.dealerCode);
										$("#addering").val(maintainDealerObj.detailAddress);
										$("#dianhua").val(maintainDealerObj.salesHotline);
										$("#shortNameFirst").html(maintainDealerObj.dealerShortName);
										$('#Tel').attr('href','tel:'+maintainDealerObj.salesHotline);
										$("#remarkFirst").html(maintainDealerObj.remark);
									}else{
								findDealerHtml = findDealerHtml + '<li data-id="'+ Km +'" style="margin: 0px;padding: 3px;">'
																+ '<div class="panel panel-default">'
																+ '<table style="width:100%" class="table-condensed"><tbody>'
																+ '<tr>'
																+ '<td style="width:160px;text-align:left;"><a onclick="sureDealer('+maintainDealerIndex+')">'
																+ '<p id="name'+ maintainDealerIndex +'" style="font-family:黑体;font-size:16px;color:#000000">' + maintainDealerObj.dealerName + '</p>'
																+ '<p class="hidden" id="shortName'+maintainDealerIndex+'">'+maintainDealerObj.dealerShortName+'</p>'
																+ '</a></td>'
																+ '<td style="width:100px;text-align:center;font-size:14px;color:#7a7a7a">'
																+ '<span>距离：</span><span>'+ distance + '</span>'
																+ '</td>'
																+ '</tr><tr>'
																+ '<td style="width:160px;text-align:left;">'
																+ '<span id="addr'+ maintainDealerIndex +'" style="font-faminly:宋体;font-size:15px;color:#615f5f">' + maintainDealerObj.detailAddress + '</span>'
																+ '</td>'
																+ '<td style="width:100px;text-align:center;">'
																+ '<a href="tel:'+ maintainDealerObj.salesHotline +'" id="Tel">'
																+ '<span class="glyphicon glyphicon-earphone" style="color: rgb(255, 0, 23); font-size: 12px;"></span>'
																+ '<span style="font-family:宋体;font-size:14px;color:#7a7a7a"> 电话</span>'
																+ '</a></td>'
																+ '</tr>'
																+ '</tbody></table>'
																+ '<input id="code'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.dealerCode + '">'
																+ '<input id="adds'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.detailAddress + '">'
																+ '<input id="pho'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.salesHotline + '">'
																+ '</div></li>'
								
								wholeHtml += findDealerHtml;
								}
							});
							$("#dealerDiv").append(wholeHtml);
						}
					});
					
		}
		
		//关闭选择经销商的div
		function closeSureDealer(obj){
			$("#nowDealerDiv").hide();
			$("#nowDealerDiv").removeClass("active in");
			 $("#maintainMainDiv").show();
			//初始化界面
			 $("#maintainMainDiv").addClass("active in");
			 $("#firstImg").show();
			 $("#list2").show();
		}
		
		//定位所在定经销商,二级页面
		function selectNowDealer(obj){
			 $("#sou").val("");
			 $("#firstImg").hide();
			 $("#maintainMainDiv").hide();
			 $("#maintainMainDiv").removeClass("active in");
			 $("#maintainDealerDiv").hide();
			 $("#maintainDealerDiv").removeClass("active in");
			 $("#nowDealerDiv").show();
			 $("#dealerDiv").html("");
			 //初始化界面
			 $("#nowDealerDiv").addClass("active in");
				//根据城市名获取所在地经销商列表
					$.ajax({
						method : 'get',
						url : rootPath+'/maintain/api/v1/maintainDealer?regionName='+ $("#regionName").val()+'&dealerCode='+ $("#dealerCode").val()+'',
						error:function(XMLHttpRequest, ajaxOptions, thrownError){
							//alert("未连接服务器!");
						},
						success : function(resultData){
							
							var wholeHtml = '';
							var  Km = '';
							$.each(resultData,function(maintainDealerIndex,maintainDealerObj){
								
								var findDealerHtml = '';
								var lat1 = maintainDealerObj.latitude;
								var lng1 = maintainDealerObj.longitude;
								var lat2 = $("#latitude").val();
								var lng2 = $("#longitude").val();
								Km = GetDistance(lat1,lng1,lat2,lng2).toFixed(2);
								if(lat1==null||lat1=="0"||lng1==null||lng1=="0"){var distance = "暂无";}
								else{var distance = Km + '千米';}
								
									if(maintainDealerObj.remark =='首选店'){
										$("#KmFirst").show();
										$("#nameFirst").html(maintainDealerObj.dealerName);
										$("#distanceFirst").html(distance);
										$("#addrFirst").html(maintainDealerObj.detailAddress);
										$("#codeFirst").val(maintainDealerObj.dealerCode);
										$("#addering").val(maintainDealerObj.detailAddress);
										$("#dianhua").val(maintainDealerObj.salesHotline);
										$("#shortNameFirst").html(maintainDealerObj.dealerShortName);
										$('#Tel').attr('href','tel:'+maintainDealerObj.salesHotline);
										$("#remarkFirst").html(maintainDealerObj.remark);
									}else{
								findDealerHtml = findDealerHtml + '<li data-id="'+ Km +'" style="margin: 0px;padding: 3px;">'
																+ '<div class="panel panel-default">'
																+ '<table style="width:100%" class="table-condensed"><tbody>'
																+ '<tr>'
																+ '<td style="width:160px;text-align:left;"><a onclick="sureDealer('+maintainDealerIndex+')">'
																+ '<p id="name'+ maintainDealerIndex +'" style="font-family:黑体;font-size:16px;color:#000000">' + maintainDealerObj.dealerName + '</p>'
																+ '<p class="hidden" id="shortName'+maintainDealerIndex+'">'+maintainDealerObj.dealerShortName+'</p>'
																+ '</a></td>'
																+ '<td style="width:100px;text-align:center;font-size:14px;color:#7a7a7a">'
																+ '<span>距离：</span><span>'+ distance + '</span>'
																+ '</td>'
																+ '</tr><tr>'
																+ '<td style="width:160px;text-align:left;">'
																+ '<span id="addr'+ maintainDealerIndex +'" style="font-faminly:宋体;font-size:15px;color:#615f5f">' + maintainDealerObj.detailAddress + '</span>'
																+ '</td>'
																+ '<td style="width:100px;text-align:center;">'
																+ '<a href="tel:'+ maintainDealerObj.salesHotline +'" id="Tel">'
																+ '<span class="glyphicon glyphicon-earphone" style="color: rgb(255, 0, 23); font-size: 12px;"></span>'
																+ '<span style="font-family:宋体;font-size:14px;color:#7a7a7a"> 电话</span>'
																+ '</a></td>'
																+ '</tr>'
																+ '</tbody></table>'
																+ '<input id="code'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.dealerCode + '">'
																+ '<input id="adds'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.detailAddress + '">'
																+ '<input id="pho'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.salesHotline + '">'
																+ '</div></li>'
								
								wholeHtml += findDealerHtml;
								}
							});
							$("#dealerDiv").append(wholeHtml);
						}
					});
					
		}
		//选择经销商，点击
		function selectMaintainDealer(obj){
			$("#cha").val("");
			$("#dealerMap").show();
			$("#KmFirst").hide();
			$("#firstImg").hide();
			$("#maintainMainDiv").hide();
			$("#maintainMainDiv").removeClass("active in");
			$("#nowDealerDiv").hide();
			$("#nowDealerDiv").removeClass("active in");
			 $("#maintainDealerDiv").show();
			 //初始化界面
			 $("#maintainDealerDiv").addClass("active in");
				
				// 选择经销商城市信息取得。
				$.ajax({
					method : 'get',
					url : rootPath+'/maintain/api/v1/maintainDealerMap?regionType=90011002',
					error:function(XMLHttpRequest, ajaxOptions, thrownError){
						//alert("获取失败!");
					},
					success : function(resultData){

						var wholeHtml = '';
						
						var city = '';
						$.each(resultData,function(maintainDealerMapIndex,maintainDealerMapObj){
							var DealerMapHtml = '';
							var str = maintainDealerMapObj.regionName;
							if(str == "") return;
							var arr = maintainDealerMapObj.aleph;
							for(var i=0;i<26;i++){
								var en = String.fromCharCode((97+i));
								if(arr == en){
									city = maintainDealerMapObj.regionName;

									DealerMapHtml = DealerMapHtml + '<li>'
																  + '<a onclick="selectDealer('+ maintainDealerMapIndex +')">'
																  + '<span style="font-size:18px;color:#7a7a7a">' + city + '</span>'
																  + '<input type="hidden" id="'+maintainDealerMapIndex + '" value="'+ maintainDealerMapObj.regionName +'">'
																  + '</a>'
																  + '</li>'
																  + '<div style="height:1px;margin:0px auto;padding:0px;background-color:#F4F4F4;overflow:hidden;"></div>'
									
									$("#"+en).append(DealerMapHtml);
								}
							}
							
						});

					}
				});		
		}
		//城市进入该城市经销商
		function selectDealer(obj){
			$("#sou").val("");
			var code = $("#"+obj).val();
			$("#regionName").val(code);
			$("#firstImg").hide();
			$("#maintainMainDiv").hide();
			$("#maintainMainDiv").removeClass("active in");
			$("#maintainDealerDiv").hide();
			$("#maintainDealerDiv").removeClass("active in");
			$("#dealerDiv").html("");
			 $("#nowDealerDiv").show();
			 $("#searchCity").html("");
			 $("#searchDealer").html("");
			 $("#list2").show();
			 //初始化界面
			 $("#nowDealerDiv").addClass("active in");
			 for(var i=0;i<26;i++){
					var en = String.fromCharCode((65+i));
					$("#"+en).html("");
			 }
			//根据编号获取所在地经销商列表
			$.ajax({
				method : 'get',
				url : rootPath+'/maintain/api/v1/maintainDealer?regionName='+code+'&dealerCode='+ $("#dealerCode").val()+'',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("未连接服务器!");
				},
				success : function(resultData){
					
					var wholeHtml = '';
					var  Km = '';
					$.each(resultData,function(maintainDealerIndex,maintainDealerObj){
						
						var findDealerHtml = '';
						var lat1 = maintainDealerObj.latitude;
						var lng1 = maintainDealerObj.longitude;
						var lat2 = $("#latitude").val();
						var lng2 = $("#longitude").val();
						Km = GetDistance(lat1,lng1,lat2,lng2).toFixed(2);
						if(lat1==null||lat1=="0"||lng1==null||lng1=="0"){var distance = "暂无";}
						else{var distance = Km + '千米';}
						
						findDealerHtml = findDealerHtml + '<li data-id="'+ Km +'">'
														+ '<div class="panel panel-default">'
														+ '<table style="width:100%" class="table-condensed"><tbody>'
														+ '<tr>'
														+ '<td style="width:160px;text-align:left;"><a onclick="sureDealer('+maintainDealerIndex+')">'
														+ '<p id="name'+ maintainDealerIndex +'" style="font-family:黑体;font-size:16px;color:#000000">' + maintainDealerObj.dealerName + '</p>'
														+ '<p class="hidden" id="shortName'+maintainDealerIndex+'">'+maintainDealerObj.dealerShortName+'</p>'
														+ '</a></td>'
														+ '<td style="width:100px;text-align:center;font-size:14px;color:#7a7a7a">'
														+ '<span>距离：</span><span>'+ distance + '</span>'
														+ '</td>'
														+ '</tr><tr>'
														+ '<td style="width:160px;text-align:left;">'
														+ '<span id="addr'+ maintainDealerIndex +'" style="font-faminly:宋体;font-size:15px;color:#615f5f">' + maintainDealerObj.detailAddress + '</span>'
														+ '</td>'
														+ '<td style="width:100px;text-align:center;">'
														+ '<a href="tel:'+ maintainDealerObj.salesHotline +'" id="Tel">'
														+ '<span class="glyphicon glyphicon-earphone" style="color: rgb(255, 0, 23); font-size: 12px;"></span>'
														+ '<span style="font-family:宋体;font-size:14px;color:#7a7a7a"> 电话</span>'
														+ '</a></td>'
														+ '</tr>'
														+ '</tbody></table>'
														+ '<input id="code'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.dealerCode + '">'
														+ '<input id="adds'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.detailAddress + '">'
														+ '<input id="pho'+ maintainDealerIndex +'" class="hidden" value="' + maintainDealerObj.salesHotline + '">'
														+ '</div></li>'
						
						wholeHtml += findDealerHtml;
					});
					$("#dealerDiv").append(wholeHtml);
				}
			});
		}
		//选中某经销商
		function sureDealer(obj){
			if(obj=='-1'){
			  var code = $("#codeFirst").val();
		 	  var name = $("#shortNameFirst").html();
		   	  var addr = $("#addrFirst").html();
		    $("#address").val($("#addering").val());
			 $("#phonenumber").val($("#dianhua").val());
			}else{
			  var code = $("#code"+obj).val();
			  var name = $("#shortName"+obj).html();
			  var addr = $("#addr"+obj).html();
			  $("#address").val($("#adds"+obj).val());
			  $("#phonenumber").val($("#pho"+obj).val());
			}
			
			//alert(code+','+name+','+addr);
			$("#dealerCode").val(code);
			$("#dealerName").html(name);
			//$("#detailAddress").html(addr);
			$("#nowDealerDiv").hide();
			$("#nowDealerDiv").removeClass("active in");
			 $("#maintainMainDiv").show();
			 //初始化界面
			 $("#maintainMainDiv").addClass("active in");
			 $("#firstImg").show();
			 $("#list2").show();
			 $("#searchDealer").html("");
		}
		//排序
		function Sort(bo)
		{
		    var arr = document.getElementById("list2").innerHTML.match(/<li>[\s\S]+?<\/li>/g);
		    arr.sort(function(a,b){
		        a = parseInt(/\d+/.exec(a)[0], 10);
		        b = parseInt(/\d+/.exec(b)[0], 10);
		        return bo?b-a:a-b;
		    });
		    document.getElementById("ol1").innerHTML = arr.join("");
		}
		//进行经纬度转换为距离的计算
		function Rad(d){
		  return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
		}
		//计算距离，参数分别为第一点的纬度，经度；第二点的纬度，经度
		function GetDistance(lat1,lng1,lat2,lng2){

		   var radLat1 = Rad(lat1);
		   var radLat2 = Rad(lat2);
		   var a = radLat1 - radLat2;
		   var  b = Rad(lng1) - Rad(lng2);
		   var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
		   Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
		   s = s *6378.137 ;// EARTH_RADIUS;
		   s = Math.round(s * 10000) / 10000; //输出为公里
		   //s=s.toFixed(4);
		   return s;
		}
		//搜索城市
		function searchCity(){
			$("#dealerMap").hide();
			$("#searchCity").html("");
			var regionName = $("#cha").val();
			$.ajax({
			    type:"GET", 
			    url:rootPath+"/maintain/api/v1/maintainSelectCity?regionName="+regionName, 
			    dataType:"json",      
			    async: false,
			    contentType:"application/json",               
			    data:null, 
			    success:function(data){ 
					var wholeHtml = '<ul class="list-group">';
					
					$.each(data,function(maintainSearchCityIndex,maintainSearchCityObj){
						var DealerMapHtml = '';
						
							DealerMapHtml = DealerMapHtml   + '<li class="list-group-item">'
															+ '<a onclick="selectDealer('+ maintainSearchCityIndex +')">'
															+ '<span style="font-size:18px;color:#7a7a7a">' + maintainSearchCityObj.regionName + '</span>'
															+ '<input type="hidden" id="'+maintainSearchCityIndex + '" value="'+ maintainSearchCityObj.regionName +'">'
															+ '</a>'
															+ '</li>'		
						       wholeHtml += DealerMapHtml;
					});
					wholeHtml = wholeHtml + '</ul>'
					$("#searchCity").append(wholeHtml);
			    },
			    error:function(data){
			    	//alert("数据刷新失败，请联系管理员！");
			    }
			 });
		}
		//搜索经销商
		function searchDealer(){
			$("#list2").hide();
			$("#searchDealer").html("");
			var dealerName = $("#sou").val();
			var regionName = $("#regionName").val();
			$.ajax({
			    type:"GET", 
			    url:rootPath+"/maintain/api/v1/searchDealer?dealerName="+dealerName+"&regionName="+regionName, 
			    dataType:"json",      
			    async: false,
			    contentType:"application/json",               
			    data:null, 
			    success:function(data){ 
					var wholeHtml = '<ul class="list-group">';
					var  Km = '';
					$.each(data,function(SearchDealerIndex,SearchDealerObj){
						var DealerMapHtml = '';
						var findDealerHtml = '';
						var lat1 = SearchDealerObj.latitude;
						var lng1 = SearchDealerObj.longitude;
						var lat2 = $("#latitude").val();
						var lng2 = $("#longitude").val();
						Km = GetDistance(lat1,lng1,lat2,lng2).toFixed(2);
						if(lat1==null||lat1=="0"||lng1==null||lng1=="0"){var distance = "暂无";}
						else{var distance = Km + '千米';}
						
							DealerMapHtml = DealerMapHtml   + '<li class="list-group-item">'
															+ '<table style="width:100%" class="table-condensed"><tbody>'
															+ '<tr>'
															+ '<td style="width:160px;text-align:left;"><a onclick="sureDealer('+SearchDealerIndex+')">'
															+ '<p id="name'+ SearchDealerIndex +'" style="font-family:黑体;font-size:16px;color:#000000">' + SearchDealerObj.dealerName + '</p>'
															+ '<p class="hidden" id="shortName'+SearchDealerIndex+'">'+SearchDealerObj.dealerShortName+'</p>'
															+ '</a></td>'
															+ '<td style="width:100px;text-align:center;font-size:14px;color:#7a7a7a">'
															+ '<span>距离：</span><span>'+ distance + '</span>'
															+ '</td>'
															+ '</tr><tr>'
															+ '<td style="width:160px;text-align:left;">'
															+ '<span id="addr'+ SearchDealerIndex +'" style="font-faminly:宋体;font-size:15px;color:#615f5f">' + SearchDealerObj.detailAddress + '</span>'
															+ '</td>'
															+ '<td style="width:100px;text-align:center;">'
															+ '<a href="tel:'+ SearchDealerObj.salesHotline +'" id="Tel">'
															+ '<span class="glyphicon glyphicon-earphone" style="color: rgb(255, 0, 23); font-size: 12px;"></span>'
															+ '<span style="font-family:宋体;font-size:14px;color:#7a7a7a"> 电话</span>'
															+ '</a></td>'
															+ '</tr>'
															+ '</tbody></table>'
															+ '<input id="code'+ SearchDealerIndex +'" class="hidden" value="' + SearchDealerObj.dealerCode + '">'
															+ '<input id="adds'+ SearchDealerIndex +'" class="hidden" value="' + SearchDealerObj.detailAddress + '">'
															+ '<input id="pho'+ SearchDealerIndex +'" class="hidden" value="' + SearchDealerObj.salesHotline + '">'
															+ '</li>'
													
							wholeHtml += DealerMapHtml;
					});
					wholeHtml = wholeHtml + '</ul>'
					$("#searchDealer").append(wholeHtml);
			    },
			    error:function(data){
			    	//alert("数据刷新失败，请联系管理员！");
			    }
			 });
			}
		
		function to_bingCar(){
			
			//window.location = rootPath + "/views/homepage/signUp.html";
			window.location = rootPath + "/views/modules/register.html";
		}
		
		/**
		 * 推荐购车画面JS
		 */
		$(document).ready(function(){
			$("#KmFirst").hide();
			//检测是否是会员
			$.ajax({
				headers: {'Cookie' : document.cookie },
				method : 'get',
				url : rootPath+'/customer/api/v1/queryUserOwner',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("数据刷新失败");
				},
				success : function(resultData){ 
					if(resultData.length==0){
						alert("请先注册会员再使用");
						to_bingCar();
					}
				}
				
			})
			//监听城市选择页面搜索输入框
			$("#cha").keyup(function(event){ 
		        if (event.keyCode === 13){ 
		       	 searchCity();
		        } 
		      }); 
			
			//监听经销商选择页面搜索输入框
			$("#sou").keyup(function(event){ 
		        if (event.keyCode === 13){ 
		       	 searchDealer();
		        } 
		      }); 
			
		//获取推荐理由
			$.ajax({
				method : 'get',
				url : rootPath+'/leads/api/v1/IscodeMap',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("数据刷新失败");
				},
				success : function(resultData){
					var wholeHtml = ' <label class="checkbox-inline">'; 
					$.each(resultData,function(memberInfoIndex,tccodedto){
					var tccodeHtml="";
					tccodeHtml=tccodeHtml+' <input type="checkbox" id="inlineCheckbox" value='+tccodedto.fullname+'> <span id="fullname" style="margin-right: 25px; position:relative; top: 3px"> '+tccodedto.fullname+'</span>'
			         wholeHtml += tccodeHtml;	
					});
					$("#TgCode").append(wholeHtml);
				}
			});
			
			
			
			$.ajax({
				headers: {'Cookie' : document.cookie },
				method : 'get',
				url : rootPath+'/customer/api/v1/memberInfo',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("数据刷新失败");
				},
				success : function(resultData){
					$.each(resultData,function(memberInfoIndex,memberInfoObj){
						if(memberInfoObj.userName==null){
							$("#username").val(memberInfoObj.nickName);
						}else {
							$("#username").val(memberInfoObj.userName);
						}
						$("#userphone").val(memberInfoObj.phone);
						$("#dealerName").html(memberInfoObj.dealerShortName);
						$("#userId").val(memberInfoObj.userId);
						$("#dealerCode").val(memberInfoObj.dealerCode);
						$("#address").val(memberInfoObj.dealerAddress);
						$("#phonenumber").val(memberInfoObj.salesHotline);
					});
				}
			});
		$("#immediatelyAppoint").click(function(){
			$("#immediatelyAppoint").attr("disabled","disabled");
			$("#immediatelyAppoint").attr("class","btnbtn1");
			$("#immediatelyAppoint").removeAttr("style");
			var friendname=$("#friendname").val();
			var userId=$("#userId").val();
			var friendphone=$("#friendphone").val();
			var recommendedcar=$("#seriesCode").val();
			var dealerCode=$("#dealerCode").val();
			var userphone=$("#userphone").val();
			var recommendedstore=$("#dealerCode").val();
			
			if(!( /^[\u0391-\uFFE5A-Za-z]+$/.test(friendname))){
				$("#immediatelyAppoint").removeAttr("disabled");
				$("#immediatelyAppoint").attr("class","btnbtn");
				alert("朋友姓名有误，请重填");
		        return false;
			}
			if(!(/^1[34578]\d{9}$/.test(friendphone))){
				$("#immediatelyAppoint").removeAttr("disabled");
				$("#immediatelyAppoint").attr("class","btnbtn");
				alert("手机号码有误，请重填");  
		        return false;
			}
			if(userphone==friendphone){
				$("#immediatelyAppoint").removeAttr("disabled");
				$("#immediatelyAppoint").attr("class","btnbtn");
				alert("推荐有礼活动不支持自我推荐，请填写好友电话。");  
		        return false;
				
			}
			if(recommendedcar==""){
				$("#immediatelyAppoint").removeAttr("disabled");
				$("#immediatelyAppoint").attr("class","btnbtn");
				alert("请选择车型！");  
		        return false;
			}
			
			if(recommendedstore==""){
				$("#immediatelyAppoint").removeAttr("disabled");
				$("#immediatelyAppoint").attr("class","btnbtn");
				alert("请选择销售店！");  
		        return false;
			}
			$.ajax({
				method : 'get',
				url : rootPath+'/leads/api/v1/ThreadPhone?&friendphone='+friendphone+'&dealerCode='+dealerCode+'',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("未连接服务器!");
				},
				success:function(resultData){
					if(resultData.length>0){
						alert( "线索已经推荐。");
						location.reload();
						return false;
					}else {
						$.ajax({
							method : 'get',
							url : rootPath+'/leads/api/v1/Createtime?friendphone='+friendphone+'&recommendedcar='+recommendedcar+'&dealerCode='+dealerCode+'',
							error:function(XMLHttpRequest, ajaxOptions, thrownError){
								//alert("未连接服务器!");
							},
							success:function(resultData){
								if(resultData.length==0){
									savethreade();
								}else{
									alert( "您已推荐该客户到该店 。");
									location.reload();
								}
							}
						})
					}
				}
				
			})
			

			
		})
		 function firm() {  
        //利用对话框返回的值 （true 或者 false）  
        if (confirm("是否继续推荐")) {  
        	 window.location.reload();
        }  
        else {  
        	window.location = "http://carowner.yonyouauto.com/wx/pub/personal?"+document.cookie;
        }  
  
    }  
		function savethreade(){
        	$("#immediatelyAppoint").attr("disabled","disabled");
			var value="";
			for (var i=0;i<inlineCheckbox.length;i++ ){
			      if(inlineCheckbox[i].checked){ //判断复选框是否选中
			      value=value+inlineCheckbox[i].value+","; 
			        }
			   } 
			var newvalue=value.substring(0,value.length-1);
			if(newvalue==""){
			    alert("请至少选择一条推荐理由");
//	        	location.reload();
			    return false;
			}
			var threadDto ={"username":$("#username").val(),"userphone":$("#userphone").val(),
					"friendname":$("#friendname").val(),"friendphone":$("#friendphone").val(),"remark":$("#remark").val(),
					"recommendedreasons":newvalue,"recommendedstore":$("#dealerCode").val(),"recommendedcar":$("#seriesCode").val(),
					"recommendedcars":$("#recommendedcar").html(),"recommendedstores":$("#dealerName").html(),"recommendedreasonss":$("#fullname").html(),
					"address":$("#address").val(),"phonenumber":$("#phonenumber").val(),
			};
			
			$.ajax({ 
		        type:"POST", 
		        url:rootPath+"/leads/api/v1/saveThread", 
		        dataType:"json",      
		        contentType:"application/json",               
		        data:JSON.stringify(threadDto), 
		        success:function(data){
		        	var datas = eval(data);
		        	alert(data.errorMsg);
		        	location.reload();
		        	//alert("推荐成功！");
		        	//firm();
		        },
		        error:function(data){
		        	$("#immediatelyAppoint").attr("disabled","disabled");
		        	alert("推荐失败！");
		        	location.reload();
		        }
		     });
		}
		
		})
		
		 
		
		